/*
 * @Author: lll 1280388921@qq.com
 * @Date: 2025-08-14 10:08:21
 * @LastEditors: lll 1280388921@qq.com
 * @LastEditTime: 2025-08-14 10:48:00
 * @FilePath: /lesson43/testjson/test.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<string>
#include<unistd.h>
#include<jsoncpp/json/json.h>

using namespace std;

int main()
{
    Json::Value p;
    p["haha"]="haha";
    p["hehe"]="hehe";

    Json::Value root;
    root["x"]=100;
    root["y"]=200;
    root["op"]='+';
    root["desc"]="this is a + oper";
    root["test"]=p;

    // Json::FastWriter w;
    Json::StyledWriter w;
    
    string s=w.write(root);

    cout<<s<<endl;

    sleep(3);

    Json::Value v;
    Json::Reader r;
    r.parse(s,v);

    int x=v["x"].asInt();
    int y=v["y"].asInt();
    int op=v["op"].asInt();
    string desc=v["desc"].asString();

    Json::Value t=v["test"];
    string s1=t["haha"].asString();
    string s2=t["hehe"].asString();

    cout<<x<<endl;
    cout<<y<<endl;
    cout<<op<<endl;
    cout<<desc<<endl;
    cout<<s1<<endl;
    cout<<s2<<endl;

    return 0;
}